package wapper.drcorator;

import wapper.componet.AbstractLogger;

public abstract class AbstractLoggerDecorator implements AbstractLogger {
    AbstractLogger abstractLogger;
    private final StringBuilder builder;

    public AbstractLoggerDecorator(AbstractLogger abstractLogger) {
        this.abstractLogger = abstractLogger;
        builder = new StringBuilder();
    }

    public StringBuilder getData() {
        return builder;
    }

    protected abstract void beforeWrapper();

    protected abstract void endWrapper();

    @Override
    public void print(String msg) {
        builder.delete(0,builder.length());//清掉缓存
        builder.append(msg);
        beforeWrapper();
        abstractLogger.print(builder.toString());
        endWrapper();

    }
}
